﻿//标识是否集成Ext
var G_Ext_Integration=false;
function Form_Onload(){
 
       if(!G_Ext_Integration){
            //处理提示消息
              PromptMessage();
   
            //显示子表数据
             showDetailTableData();
       }


 }
 /**
   执行Foothill Engine Register JavaScript
 */
 function ExecuteEngineRegisterJavaScript(){
         //执行后台注册的Javascript
  
      if(document.getElementById("FoothillBackJavaScript") !=null){
         var fJavascript= document.getElementById("FoothillBackJavaScript").value;
         
        if(fJavascript !=null && fJavascript !=""){
            eval(fJavascript);
         }
      }
 }
 /**
   显示明细错误
 */
 function ShowDetailError(){
    var detailError= document.getElementById("DetailErrorMessage").innerHTML;
    FoothillAlert(detailError);
 }
function PromptMessage(){
    var msg= document.getElementById("PromptMessage").innerHTML;
     var detailError= document.getElementById("DetailErrorMessage").innerHTML;
     if(msg !=""){
         //操作失败
         if(!PageExecuteSuccess){
//           msg= jQuery.format("{0}<br><span style='width:200' align=right><a href='#' onclick='ShowDetailError();'>详细错误</a></span>",msg,detailError);
            ShowErrorMessage('错误', msg, detailError);
         }else
            FoothillAlert(msg);
            
              
      }
         //执行Foothill Engine Register JavaScript
      ExecuteEngineRegisterJavaScript();
}

function ShowErrorMessage(title, message, detailMessage)
    {
        var html = '<table width="200" border="0"><tr><td style="padding-left:10px;width:40px;">';
        html += '<div style="height:40px;" class="ext_div_ico_error"/>&nbsp;';
        html += '</td><td style="padding-left:10px;">' + message + '</td></tr></table>';
        html += '<div id="showMessageId" style="display:none;">';
        html += '<textarea style="height:90px;width:280px;" class="x-form-textarea x-form-field" readonly="true">错误详细信息\n\n' + detailMessage + '</textarea></div>';
        var win = new Ext.Window({
            title: title,
            autoCreate : true,
            resizable:false,
            constrain:true,
            constrainHeader:true,
            minimizable : false,
            maximizable : false,
            stateful: false,
            modal: true,
            shim:true,
            buttonAlign:"center",
            width:300,
            height:110,
            minHeight: 80,
            plain:true,
            footer:true,
            closable:true,
            border: false,
            html: html,
            buttons: [{
                minWidth: 120,
                id :'PublicShowHideError',
                text:'显示失败原因',
                onClick: function(){
                    if(document.getElementById('showMessageId').style.display == ''){
                        document.getElementById('showMessageId').style.display = 'none';
                        Ext.getCmp("PublicShowHideError").setText("显示失败原因");
                        win.setSize(300,110);
                    }else{
                        document.getElementById('showMessageId').style.display = '';
                        Ext.getCmp("PublicShowHideError").setText("隐藏失败原因");
                        win.setSize(300,210);
                    }
                }
            },{
                text: '确 定',
                onClick: function(){
                    win.close();
                }
            }]
        });
        win.show();
    }

function AlertMessage(title,message){
    //FoothillAlert(message);
//    Ext.MessageBox.alert(title, message, null);
    new FoothillMessageBox().info(title, message);
} 
/*
  弹出模式窗口
*/
function FoothillShowModalDialog(url,Arguments,Features){

  if(!Arguments){
        Arguments="";
  }
  if(!Features){
        Features="";
  }  
 
         window.showModalDialog(url,Arguments,Features);

       /**
         关闭模式窗口以后执行的脚本
       */
       var obj = document.all("Foothill_SearchButton");
   
       if(obj !=null){
           obj.click();
       }
}

function FoothillAlert(title,message){
//   Ext.MessageBox.alert(title,message);
   new FoothillMessageBox().info(title, message);
}
function FoothillAlert(message){
//    Ext.MessageBox.alert("提示",message);
    new FoothillMessageBox().info("提示", message);
}
function FoothillConfirm(message){
//   return confirm(message);
    return FoothillMessageBox().confirm("确认", message);
}
function Foothill_BeforeSubmit(form){
  var ret= validater(form);
  if(ret){
     //校验通过后做些预处理
      
       setDetailTableRecords(); //设置明细表提交到后台的记录数
  }
  return ret;
}

function createElement(type, name) {   
   var element = null;   
  
   try {   
      // First try the IE way; if this fails then use the standard way   
      element = document.createElement('<'+type+' name="'+name+'">');   
   } catch (e) {   
      // Probably failed because we’re not running on IE   
   }   
   if (!element) {   
      element = document.createElement(type);   
      element.name = name;   
   }   
   return element;   
} 
//  DOM没有提供insertAfter()方法，所以我们只能自己写一个。
function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
// 如果最后的节点是目标元素，则直接添加。因为默认是最后
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
//如果不是，则插入在目标元素的下一个兄弟节点 的前面。也就是目标元素的后面。
  }
}

  /**
     重置MntEntity对应的html表单元素
  */
  function ResetFoothillForm(){
    document.location.href= document.location.href;
  /*
      var f=new FoothillFormDefTool(foothillPageDef);
   
        f.ResetAllEntityForm();
        */
  }
  

     /***
     限制text,textarea允许输入内容长度
   */
   function Restrict_Length(element,len){
      if(element.value.length >= len)
      event.returnValue = false;

   }
   
   //Foothill消息框
   function FoothillMessageBox(){
        this.info = function(strTitle, strMessage){
            Ext.MessageBox.show({
                           title: strTitle,
                           msg: strMessage,
                           buttons: Ext.MessageBox.OK,
                           icon: Ext.MessageBox.INFO
            });
        }
        
        this.warning = function(strTitle, strMessage){
            Ext.MessageBox.show({
                           title: strTitle,
                           msg: strMessage,
                           buttons: Ext.MessageBox.OK,
                           icon: Ext.MessageBox.WARNING
            });
        }
        
        this.confirm = function(strTitle, strMessage){
            return Ext.MessageBox.show({
                           title: strTitle,
                           msg: strMessage,
                           buttons: Ext.MessageBox.OKCANCEL,
                           icon: Ext.MessageBox.QUESTION
            });
        }
        
        this.error = function(strTitle, strMessage, strDetailMessage){
            ShowErrorMessage(strTitle, strMessage, strDetailMessage);
        }

   }